Skip to content

charset is not invalid in text/javascript MIME #39505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
peter-lyons-kehl opened this issue May 13, 2025 · 1 comment
Open

charset is not invalid in text/javascript MIME #39505

peter-lyons-kehl opened this issue May 13, 2025 · 1 comment
Labels
Content:HTTP HTTP docs goal: accuracy (Experimental label) Issues about inaccurate/incorrect content. help wanted If you know something about this topic, we would love your help!

Comments

@peter-lyons-kehl
Copy link
Contributor

peter-lyons-kehl commented May 13, 2025

https://github.com/mdn/content/blob/main/files/en-us/web/http/guides/mime_types/index.md, rendered as https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types, is incorrect in part textjavascript:

"Per the IANA Media Types registry, RFC 9239, and the HTML specification, JavaScript content should always be served using the MIME type text/javascript. No other MIME types are considered valid for JavaScript, and using any MIME type other than text/javascript may result in scripts that do not load or run.

You may find some JavaScript content incorrectly served with a charset parameter as part of the MIME type — as an attempt to specify the character set for the script content. That charset parameter isn't valid for JavaScript content, and in most cases will result in a script failing to load."

The three links above (in the respective order):

  • IANA Media Types registry > the only occurrence of text/javascript links to https://www.iana.org/assignments/media-types/text/javascript, which reads: "Optional parameters: charset."

  • RFC 9239 > "The charset parameter is only used when processing a Script goal source; Module goal sources MUST always be processed as UTF-8." (bold formatting is mine)

  • HTML specification > (the rest of this list item is one consecutive quote) > For external JavaScript resources, MIME type parameters in Content-Type headers are generally ignored. (In some cases the charset parameter has an effect.) However, for the script element's type attribute they are significant; it uses the JavaScript MIME type essence match concept.

    For example, scripts with their type attribute set to "text/javascript; charset=utf-8" will not be evaluated, even though that is a valid JavaScript MIME type when parsed.

    • that means "type attribute" of a <script type="..."> tag in HTML source. Specifically, "their type" links to HTML definition of type attribute of <script> element. NOT MIME as served by web server (or as specified in data: URLs).

I'm willing to provide a pull request.

@github-actions github-actions bot added Content:HTTP HTTP docs needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels May 13, 2025
@peter-lyons-kehl peter-lyons-kehl changed the title content/files/en-us/web/http/guides/mime_types/index.md Incorrect: charset in text/javbascript MIME: content/files/en-us/web/http/guides/mime_types/index.md May 13, 2025
@peter-lyons-kehl peter-lyons-kehl changed the title Incorrect: charset in text/javbascript MIME: content/files/en-us/web/http/guides/mime_types/index.md Incorrect: charset in text/javascript MIME: content/files/en-us/web/http/guides/mime_types/index.md May 13, 2025
@Josh-Cena Josh-Cena removed the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label May 14, 2025
@Josh-Cena Josh-Cena changed the title Incorrect: charset in text/javascript MIME: content/files/en-us/web/http/guides/mime_types/index.md charset is not invalid in text/javascript MIME May 14, 2025
@Josh-Cena Josh-Cena added the help wanted If you know something about this topic, we would love your help! label May 14, 2025
@Josh-Cena
Copy link
Member

Yes, it appears that this paragraph is talking about type in <script>, not Content-Type. PRs welcome.

@caugner caugner added the goal: accuracy (Experimental label) Issues about inaccurate/incorrect content. label May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:HTTP HTTP docs goal: accuracy (Experimental label) Issues about inaccurate/incorrect content. help wanted If you know something about this topic, we would love your help!
Projects
None yet
Development

No branches or pull requests

3 participants